#pragma once
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <cstring>
#include <unistd.h>
#include <iostream>
#include <sys/stat.h>
#include <fcntl.h>
using namespace std;

const string pathname = "./home/for_pipe/sharedmemory";
const int proj_id = 1234;
const size_t size = 4096;
const string pipepath = "./myfifo";

class Init {
public:
    Init(): key(ftok(pathname.c_str(), proj_id)), shmid(shmget(key, size, IPC_CREAT|IPC_EXCL|0666)){
        int ret = mkfifo(pipepath.c_str(), 0666);
        if (ret < 0) {
            cout << "make namedfifo fail"<< endl;
            exit(1);
        }
    }
    ~Init() {
        shmctl(shmid, IPC_RMID, nullptr);
        unlink(pipepath.c_str());
    }
    int key;
    int shmid;
};